package com.glodon.paas.exception;

import com.glodon.paas.exception.i18n.ErrorCode;

public class PaasServerExceptionFactory {
	
	/**
	 * account模块通用异常
	 * @param message
	 * @param cause
	 * @return
	 */
	public static PaasServerException accountException(String message, Throwable cause){
		return new AccountException(ErrorCode.ACCOUNT_ERROR, message, cause);
	}
	
	/**
	 * document模块通用异常
	 * @param message
	 * @param cause
	 * @return
	 */
	public static PaasServerException documentException(String message,  Throwable cause){
		return new DocumentException(ErrorCode.DOCUMENT_ERROR, message, cause);		
	}
	
	
	public static PaasServerException systemException(String message, Throwable cause){
		return new SystemException(ErrorCode.SYSTEM_ERROR, message, cause);
	}
	
	public static PaasServerException accessForbidden(String message, Throwable cause){
		return new ForbiddenException(ErrorCode.ACCESS_FORBIDDEN, message, cause);
	}
	
	/**
	 * 数据库访问异常
	 * @param message
	 * @param cause
	 * @return
	 */
	public static PaasServerException dbException(String message,  Throwable cause){
		return new DataBaseException(ErrorCode.PERSISTENCE_ERROR, message, cause);		
	}
	
	/**
	 * 数据不存在
	 * @param message
	 * @param cause
	 * @return
	 */
	public static PaasServerException notFoundException(String message,  Throwable cause){
		return new NotFoundException(ErrorCode.NOT_FOUND, message, cause);		
	}

	/**
	 * 数据校验失败
	 * @param msg
	 * @return
	 */
	public static PaasServerException validateException(String message,  Throwable cause){
		return new ValidateException(ErrorCode.VALIDATE_ERROR, message, cause);
	}
	
	/**
	 * 没有该操作权限
	 * @param msg
	 * @return
	 */
	public static PaasServerException privilegeException(String message,  Throwable cause){
		return new PrivilegeException(ErrorCode.PRIVILEGE_ERROR, message, cause);
	}

	/**
	 * 存储平台
	 * @param msg
	 * @return
	 */
	public static PaasServerException mergePartsException(String message,  Throwable cause){
		return new MergePartsException(ErrorCode.STORAGE_ERROR, message, cause);
	}
	
	/**
	 * 存储平台
	 * @param msg
	 * @return
	 */
	public static PaasServerException storageException(String message,  Throwable cause){
		return new StorageException(ErrorCode.STORAGE_ERROR, message, cause);
	}
	
	/**
	 * 内部API调用
	 * @param msg
	 * @return
	 */
	public static PaasServerException internalAPIException(String message,  Throwable cause){
		return new InternalAPIException(ErrorCode.INTERNAL_API_ERROR, message, cause);
	}
	
	/**
	 * 内部API调用
	 * @param msg
	 * @return
	 */
	public static PaasServerException externalAPIException(String message,  Throwable cause){
		return new InternalAPIException(ErrorCode.EXTERNAL_API_ERROR, message, cause);
	}
	
	/**
	 * 数据重复
	 * @param msg
	 * @return
	 */
	public static PaasServerException existException(String message,  Throwable cause){
		return new ExistException(ErrorCode.DATA_DUPLICATION, message, cause);
	}
	
	/**
	 * 
	 * @param msg
	 * @return
	 */
	public static PaasServerException unImplementedException(String message,  Throwable cause){
		return new PaasUnImplementedException(ErrorCode.UNIMPLEMENT, message, cause);
	}
	

	/**
	 * 
	 * @param msg
	 * @return
	 */
	public static PaasServerException unknownException(String message,  Throwable cause){
		return new UnknownException(ErrorCode.UNDEFINED_ERROR, message, cause);
	}
	
	/**
	 * 
	 * @param msg
	 * @return
	 */
	public static PaasServerException authenticationException(String message,  Throwable cause){
		return new UnknownException(ErrorCode.UNDEFINED_ERROR, message, cause);
	}
	
	/**
	 * 系统尚未支持
	 * 
	 * @param msg
	 * @return
	 */
	public static PaasServerException nosupport(String message){
		return new UnknownException(ErrorCode.NO_SUPPORT, "system not support:"+message, null);
	}
}
